package com.hardydou.learn.annotation.processor;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import java.util.Set;

@SupportedAnnotationTypes({"com.hardydou.learn.annotation.processor.EnableAuthor"})
public class AuthorProcessor extends AbstractProcessor {
    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.latestSupported();
    }

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(EnableAuthor.class);

        for (Element ele : elements) {
            if (ele.getKind() == ElementKind.CLASS) {
                EnableAuthor author = ele.getAnnotation(EnableAuthor.class);
                System.out.println(ele + "[{author:" + author.name() + "email:" + author.email() + "}");
            }
        }
        return true;
    }
}
